import React from 'react';
import { HashRouter as Router, Route } from 'react-router-dom';
import { Provider } from 'react-redux';
import Loadable from 'react-loadable';
import store from '../store';

const Loading = () => null;

// 登入
const Login = Loadable({
  loader: () => import('./Auth/Login'),
  loading: Loading,
});

// 注册
const Register = Loadable({
  loader: () => import('./Auth/Register'),
  loading: Loading,
});

// 主界面
const Main = Loadable({
  loader: () => import('./Main'),
  loading: Loading,
});

const token = localStorage.getItem('token');

//初始化state状态
if (token) {
  store.dispatch({ type: '#auth' });
}

const App = () => (
  <Provider store={store}>
    <Router>
      <div>
        <Route exact path="/" component={Main}/>
        <Route exact path="/register" component={Register} />
        <Route exact path="/login" component={Login} />
      </div>
    </Router>
  </Provider>
);


export default App;

